const { reject } = require('lodash');
var _util = require('util/util.js');

var _order_service = {
    getOrders: function (status, resolve, reject) {
        _util.request({
            url: _util.getServerURL("/orders?status=" + status),
            method: "GET",
            success: resolve,
            error: reject
        });
    },
    getOrderDetail: function (orderID, resolve, reject) {
        _util.sync_request({
            url: _util.getServerURL("/orders/" + orderID),
            method: "GET",
            success: resolve,
            error: reject
        });
    },
    deleteOrder: function (orderID, resolve, reject) {
        _util.request({
            url: _util.getServerURL("/orders/" + orderID + "/cancel"),
            method: "POST",
            success: resolve,
            error: reject
        });
    },
    returnOrder: function (orderID, content, resolve, reject) {
        _util.request({
            url: _util.getServerURL("/orders/" + orderID + "/return"),
            method: "POST",
            success: resolve,
            error: reject,
            data: content
        });
    },
    getReceivings: function (resolve, reject) {
        _util.request({
            url: _util.getServerURL("/orders/receivings"),
            method: "GET",
            success: resolve,
            error: reject
        });
    },
    getReceiving: function (receivingID, resolve, reject) {
        _util.request({
            url: _util.getServerURL("/orders/receivings/" + receivingID),
            method: "GET",
            success: resolve,
            error: reject
        });
    },
    postReceiving: function (receivingVO, resolve, reject) {
        _util.request({
            url: _util.getServerURL("/orders/receivings/" + receivingVO.receivingid),
            method: "POST",
            data: receivingVO,
            success: resolve,
            error: reject
        });
    },
    postPay: function (orderID, resolve, reject) {
        _util.request({
            url: _util.getServerURL("/orders/" + orderID + "/pay"),
            method: "POST",
            success: resolve,
            error: reject
        });
    },
    postAlipay: function (orderID, total, resolve, reject) {
        _util.request({
            url: _util.getServerURL("/orders/" + orderID + "/alipay"),
            method: "POST",
            success: resolve,
            error: reject,
            data: {
                total: total
            }
        });
    },
    //获取当前卖家全部订单
    getAllOrders: function (status, resolve, reject) {
        _util.request({
            url: _util.getServerURL('/orders/seller?status=' + status),
            method: "GET",
            success: resolve,
            error: reject,
        });
    },
    //卖家发货
    deliver: function (orderid, resolve, reject) {
        _util.request({
            url: _util.getServerURL('/orders/' + orderid + '/deliver'),
            method: "POST",
            success: resolve,
            error: reject,
        });
    },
    //确认退货
    confirmReturn: function (orderid, resolve, reject) {
        _util.request({
            url: _util.getServerURL('/orders/' + orderid + '/confirmreturn'),
            method: "POST",
            success: resolve,
            error: reject,
        });
    },
    //拒绝退货
    refuseReturn: function (orderid, refusalreason, resolve, reject) {
        _util.request({
            url: _util.getServerURL('/orders/' + orderid + '/refusereturn'),
            data: { refusalreason },
            method: "POST",
            success: resolve,
            error: reject,
        });
    },
    getRefundInfo: function (orderid, resolve, reject) {
        _util.request({
            url: _util.getServerURL('/orders/refund/' + orderid),
            method: "GET",
            success: resolve,
            error: reject,
        });
    },

};

module.exports = _order_service;